package com.yuanduan.mplus.view;

import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.cj.framework.app.BaseActivity;
import com.yuanduan.mplus.R;

/**
 * 资讯详情界面
 */
public class ConsultDetailActivity extends BaseActivity {
    private Toolbar toolbar;
    private String contentUrl;
    private WebView webView;
    @Override
    protected void findId() {
        toolbar= (Toolbar) findViewById(R.id.toolbar);
        webView= (WebView) findViewById(R.id.consultdetail_wv);
    }

    @Override
    protected void logic() {
        contentUrl=getIntent().getExtras().getString("contentUrl");
        Log.d("ConsultActivity","detailurl"+contentUrl);
        toolbar.setTitle("资讯");
        toolbar.setNavigationIcon(R.mipmap.back_arrow_black);
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ConsultDetailActivity.this.finish();
            }
        });

        initWebView();
    }

    private void initWebView() {
        //开启js脚本功能
        WebSettings settings=webView.getSettings();
        settings.setJavaScriptEnabled(true);
        //设置url
        webView.loadUrl(contentUrl);

        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_consult_detail;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode==KeyEvent.KEYCODE_BACK&&webView.canGoBack()){
            webView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
